from sessionhandling import LilCookies
from oauth.config import APPLICATION_SETTINGS

class SessionCookie:
    
    @staticmethod
    def get_cookie(name, request_handler):
        try:
            cookieutil = LilCookies(request_handler, APPLICATION_SETTINGS['cookie_secret'])
            value = cookieutil.get_secure_cookie(name)
        
            SessionCookie.set_cookie(name, value, request_handler)
        
            return value
        except:
            return None
    
    @staticmethod
    def set_cookie(name, value, request_handler):
        cookieutil = LilCookies(request_handler, APPLICATION_SETTINGS['cookie_secret'])
        cookieutil.set_secure_cookie(name, value, APPLICATION_SETTINGS['cookie_expire_days'])
    
    @staticmethod
    def expire_cookie(request_handler):
        cookieutil = LilCookies(request_handler, APPLICATION_SETTINGS['cookie_secret'])
        cookieutil.clear_all_cookies()